﻿using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Shapes;
using Model;
using Presenters.WPF;
using Presenters.WPF.Views;

namespace AirlinePilotAcademy_WPF.UI_Administrator.Students
{
    /// <summary>
    /// Interaction logic for SearchStudents.xaml
    /// </summary>
    public partial class SearchStudents : Window, ISearchStudentsView
    {
        SearchStudentsPresenter presenter;
        string Message;

        public SearchStudents(bool usesThisInterface)
        {
            InitializeComponent();
            presenter = new SearchStudentsPresenter(this);
            presenter.SearchStudent();
            this.NewInscriptionB.Visibility = Visibility.Visible;
            this.ModifyDataB.Visibility = Visibility.Hidden;
            
        }
        public SearchStudents()
        {
            InitializeComponent();
            presenter = new SearchStudentsPresenter(this);
           // presenter.SearchStudentByName();
            presenter.SearchStudent();
        }
        public string searchTextBox
        {
            get { return this.searchTB.Text; }
        }
        public bool isSearchByName
        {
            get { return this.searchByNameRB.IsChecked == true; }
        }
        public bool isSearchByID
        {
            get { return this.searchByIdRB.IsChecked == true; }
        }
        public Collection<Student> studentResults
        {
            set { this.StudentsResultsDG.ItemsSource = value; }
        }
        public string message
        {
            set { Message = value; }
        }
        public Student selectedStudent
        {
            get { return (Student)this.StudentsResultsDG.SelectedItem;}
        }


        
        private void searchTB_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (presenter != null)
            {
                presenter.SearchStudent();
            }
        }

        private void ModifyDataB_Click(object sender, RoutedEventArgs e)
        {
            if (this.StudentsResultsDG.SelectedItem != null)
            {
                NewStudent ns = new NewStudent((Student)this.StudentsResultsDG.SelectedItem);
                ns.ShowDialog();
                this.Close();
            }
            else
                MessageBox.Show("Primero Seleccione un estudiante!");

        }
        private void NewInscriptionB_Click(object sender, RoutedEventArgs e)
        {
            if (this.StudentsResultsDG.SelectedItem != null)
            {
                NewInscription ni = new NewInscription((Student)this.StudentsResultsDG.SelectedItem);
                ni.ShowDialog();
                this.Close();
            }
            else
                MessageBox.Show("Primero Seleccione un estudiante!");
        }
        private void ViewStudentsData_Click(object sender, RoutedEventArgs e)
        {
            if (this.StudentsResultsDG.SelectedItem != null)
            {
                NewStudent ns = new NewStudent((Student)this.StudentsResultsDG.SelectedItem, "isView");
                ns.ShowDialog();
            }
            else
                MessageBox.Show("Primero Seleccione un estudiante!");
        }
        private void searchTB_PreviewTextInput(object sender, TextCompositionEventArgs e)
        {
            if (this.searchByNameRB.IsChecked == true)
            {
                foreach (char ch in e.Text)
                {
                    if (!Char.IsLetter(ch))
                    {
                        e.Handled = true;
                    }
                }
            }
            if (this.searchByIdRB.IsChecked == true)
            {
                foreach (char ch in e.Text)
                {
                    if (!Char.IsDigit(ch))
                    {
                        e.Handled = true;
                    }
                }
            }
        }

       
    }
}
